package com.ruitu.arad.api.okhttp.builder;

import com.ruitu.arad.api.okhttp.MyOkHttp;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 带有param的base request body
 * Created by tsy on 2016/12/6.
 */
public abstract class OkHttpRequestBuilderHasParam<T extends OkHttpRequestBuilderHasParam> extends OkHttpRequestBuilder<T> {

    protected Map<String, String> mParams;
    protected String mJsonParams = "";

    public OkHttpRequestBuilderHasParam(MyOkHttp myOkHttp) {
        super(myOkHttp);
    }

    /**
     * set Map params
     * @param params
     * @return
     */
    public T params(Map<String, String> params) {
        this.mParams = params;
        return (T) this;
    }

    /**
     * add param
     * @param key param key
     * @param val param val
     * @return
     */
    public T addParam(String key, String val) {
        if (this.mParams == null)
        {
            mParams = new LinkedHashMap<>();
        }
        mParams.put(key, val);
        return (T) this;
    }

    /**
     * json格式参数
     * @param json
     * @return
     */
    public T jsonParams(String json) {
        this.mJsonParams = json;
        return (T)this;
    }
}
